//
//  XTStatusToolBar.swift
//  Weibo(Swift)
//
//  Created by 肖霆 on 16/5/15.
//  Copyright © 2016年 肖霆. All rights reserved.
//

import UIKit

class XTStatusToolBar: UIView {

   
    private lazy var btn1:UIButton = self.addChildBtn("timeline_icon_retweet", title: "转发")
    private lazy var btn2:UIButton = self.addChildBtn("timeline_icon_comment", title: "评论")
    private lazy var btn3:UIButton = self.addChildBtn("timeline_icon_unlike", title: "赞")

    
    
    
    var statusViewModel:XTStatusViewModel?{
        didSet{
            btn1.setTitle(statusViewModel?.retweetCount, forState: .Normal)
            btn2.setTitle(statusViewModel?.commentCount, forState: .Normal)
            btn3.setTitle(statusViewModel?.unlikeCount, forState: .Normal)
        }
    
    }
   
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        
        btn1.snp_makeConstraints { (make) -> Void in

            make.top.equalTo(self)
            make.leading.equalTo(self)
            make.trailing.equalTo(btn2.snp_leading)
            make.bottom.equalTo(self)
        }
        
        btn2.snp_makeConstraints { (make) -> Void in
          
            make.top.equalTo(btn1)
            make.leading.equalTo(btn1.snp_trailing)
            make.size.equalTo(btn1)
            make.trailing.equalTo(btn3.snp_leading)
        }
        btn3.snp_makeConstraints { (make) -> Void in

            make.top.equalTo(btn2)
            make.trailing.equalTo(self)
            make.size.equalTo(btn2)
        }
        
        
        
        
        
    
    }
    
    //创建子视图按钮的方法
    private func addChildBtn(imgName:String,title:String)->UIButton{
        
        let btn:UIButton = UIButton()
        btn.setImage(UIImage(named: imgName), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        btn.setTitle(title, forState: .Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(15)
        
        addSubview(btn)
    
    return btn

    }
}
